import React, { Component, PureComponent } from 'react'

function withRenderTime(WrappedComponent) {
  return class extends PureComponent {
    // 即将渲染获取时间
    componentWillMount() {
      this.beginTime = Date.now()
    }
    // 渲染完成获取时间
    componentDidMount() {
      this.endTime = Date.now()
      const interval = this.endTime - this.beginTime
      console.log("Home渲染时间", interval)
    }

    render() {
      return <WrappedComponent {...this.props} />
    }
  }
}

class Home extends PureComponent {
  render() {
    return (
      <h2>Home:</h2>
    )

  }
}

const TimeHome = withRenderTime(Home)

class About extends PureComponent {
  render() {
    return <h2>About:</h2>
  }
}
const TimeAbout = withRenderTime(About)

// const EnhanceAbout = enhanceRegionProps(About)

class App extends Component {
  render() {
    return (
      <div>
        App:
        <TimeHome />
        <TimeAbout />
      </div>
    )
  }
}

export default App
